'''
Description: 
Author: notplus
Date: 2021-12-09 18:20:23
LastEditors: notplus
LastEditTime: 2021-12-14 18:56:29
FilePath: /extra_eval.py

Copyright (c) 2021 notplus
'''

import pickle
import numpy as np
import matplotlib.pyplot as plt
from sklearn.cluster import DBSCAN

import utils
from extra_stay_points import User, Trajectory, StayPoint

# pickle_filename = 'activity.pickle'
pickle_filename = 'activity_153_date.pickle'

with open(pickle_filename, 'rb') as f:
    users = pickle.load(f)

all_activity = []
for user in users:
    all_activity += (user.trajs.stay_points)

all_activity.sort(key = lambda act : act.lev_t - act.arv_t)

time_interval = []
# for activity in all_activity:
for user in users:
    i = 0
    for i in range(len(user.trajs.stay_points)-1):
        time_interval.append((user.trajs.stay_points[i+1].arv_t - user.trajs.stay_points[i].lev_t).total_seconds() / 60)

time_interval.sort(reverse=True)

x = []
y = []
for activity in all_activity:
    if activity.lat > 39 and activity.lat < 41 and activity.lng > 116 and activity.lng < 117:
        x.append(activity.lng)
        y.append(activity.lat)

arrv_t = []
stay_t = []
for activity in all_activity:
    stay = (activity.lev_t - activity.arv_t).total_seconds() / 3600
    if stay < 24:
        arrv_t.append(((activity.arv_t - activity.arv_t.replace(hour=0, minute=0, second=0, microsecond=0)).total_seconds() / 3600 ))
        stay_t.append(stay)

plt.figure()
plt.scatter(np.arange(len(time_interval)), time_interval[:], s=1, marker='o', facecolors='none', edgecolors='r')
plt.figure()
plt.scatter(x, y, s=1, marker='o', facecolors='none', edgecolors='r')
plt.figure()
plt.scatter(arrv_t, stay_t, s=1, marker='o', facecolors='none', edgecolors='r')
plt.show()
print('111')

